<template>

	<view>
		<view v-if="isLoading" style="width: 100%;height: calc(100vh);position: absolute;z-index: 10000;">
			<image src="../../../static/icon/loading.png" style="width: 110rpx;height: 110rpx;" class="loading" mode="">
			</image>
		</view>
		<view @click="close1()" v-if="isShow" style="width: 100%;height: calc(100vh);position: absolute;z-index: 98;">
		</view>

		<view class="TC" style="position: relative;
    z-index: 99;" v-show="isShow">
			<view class="box">

				<view class="box1">
					<view class="box1-a">
						<view style="font-size: 40rpx;
    color: #a485ed;">
							提示
						</view>
						<view style="font-size: 40rpx;
    color: #a485ed;">
							{{msg}}
							<!-- 图片代替 -->
							<!-- <image 
								src="../../../static/icon/视频.jpg" alt=""> -->
							<!-- 视频 -->

						</view>

						<view class="btnA">
							<button type="button" style="color: #FFFFFF; " @click="close1()">确认</button>
						</view>
					</view>

				</view>
			</view>
		</view>
		<view class="mack-a" :style=" 'filter: blur('+this.$store.state.mackNum1+'px);'">
			<NavBar></NavBar>
			<view class="title">
				<view class="til">
					<image src="../../../static/icon/regi_icon/userlogin.png" mode=""></image>
					<text>登录</text>
				</view>
			</view>

			<view class="box">

				<view class="box1">
					<view class="box1-a">
						<view class="wrapper">
							<u-sticky :enable="enable" bgColor="#fff">
								<view>
									<u-tabs ref="tabs" height="64" gutter="30" bar-width="150" bar-height="5"
										:is-scroll="false" :active-item-style="barStyle" :bold="false" :list="list"
										active-color="#9471fe" inactive-color="#D3D5E0" @change="sectionChange"
										font-size="38" :current="current">
									</u-tabs>
								</view>
								<!-- <u-tabs ref="tabs" :list="list" bar-width="40rpx" active-color="#9471fe"
								inactive-color="#D3D5E0" bar-height="6rpx" @change="sectionChange" font-size="30rpx"
								is-scroll="false" :current="current"></u-tabs> -->
								<!-- <u-tabs-swiper ref="tabs"  :current="current" @change="sectionChange" inactive-color="#D3D5E0" :list="list"  bar-height="6" bar-width="80" active-color="#9471fe" is-scroll="false"></u-tabs-swiper> -->
							</u-sticky>
						</view>

						<view v-if="current==0">
							<form>
								<view class="username">
									<image src="../../../static/icon/zh.png" mode=""></image>
									<text>账&nbsp;号:</text>
									<input v-model="dataFrom.username" placeholder="请输入账号" @input="fpNumInput"
										type="text" style="text-indent: 48rpx; width: 316rpx;
						height: 84rpx;
						margin-left: 22rpx;
						border-radius: 10rpx;
						box-shadow: inset 0px 2px 5px #9e9e9e80;" />
								</view>
								<view class="password">
									<image src="../../../static/icon/password1.png" mode=""></image>
									<text>密&nbsp;码:</text>
									<view>
										<input v-model="dataFrom.password" :password="flag" placeholder="请输入密码" style="text-indent: 48rpx;  width: 316rpx;
										height: 84rpx;
										margin-left: 22rpx;
										border-radius: 10rpx;
										box-shadow: inset 0px 2px 5px #9e9e9e80;" />
									</view>
									<view style="position: absolute;right: 6px;" @click="passShow">
										<uni-icons v-if="flag" type="eye-slash" size="24" color="#a485ed"></uni-icons>
										<uni-icons v-else type="eye" size="24" color="#a485ed"></uni-icons>
									</view>
								</view>
							</form>
							<!--  -->
							<view class="remember-psw" style="padding-left: 68rpx;
    margin-top: 36rpx;color: #7948ea;">
								<checkbox-group @change="checkboxChange">
									<checkbox id="chkRem" :checked='rememberPsw' @tap="rememberPsw =! rememberPsw" type="checkbox" color="#7948ea" />
									记住密码
								</checkbox-group>
							</view>
							<view class="sms">
								<navigator url="/pages/LoginRegistration/register/register">注册</navigator>
							</view>
							<view class="btnA">
								<button type="button" style="color: #FFFFFF; " @click="login()">登&nbsp;录</button>
							</view>
						</view>

						<view v-else-if="current==1">
							<form>
								<view class="username">
									<image src="../../../static/icon/regi_icon/iconfont-phone.png" mode=""></image>
									<text>手&nbsp;机:</text>
									<input v-model="dataFrom1.mobile" @input="iponeinput" placeholder="请输入手机号"
										type="number" style="text-indent: 48rpx; width: 316rpx;
						height: 84rpx;
						margin-left: 22rpx;
						border-radius: 10rpx;
						box-shadow: inset 0px 2px 5px #9e9e9e80;" />
								</view>
								<view class="password">
									<image src="../../../static/icon/password1.png" mode=""></image>
									<text>密&nbsp;码:</text>

									<input v-model="dataFrom1.password" :password="flag" placeholder="请输入密码" style="text-indent: 48rpx;  width: 316rpx;
										height: 84rpx;
										margin-left: 22rpx;
										border-radius: 10rpx;
										box-shadow: inset 0px 2px 5px #9e9e9e80;" />

									<view style="position: absolute;right: 6px;" @click="passShow">
										<uni-icons v-if="flag" type="eye-slash" size="24" color="#a485ed"></uni-icons>
										<uni-icons v-else type="eye" size="24" color="#a485ed"></uni-icons>
									</view>
								</view>
							</form>
							<view class="remember-psw" style="padding-left: 68rpx;
							margin-top: 36rpx;color: #7948ea;">
													<checkbox-group @change="checkboxChange1">
														<checkbox id="chkRem" :checked='rememberPsw1' @tap="rememberPsw1 =! rememberPsw1" type="checkbox" color="#7948ea" />
														记住密码
													</checkbox-group>
												</view>
							<view class="sms">
								<navigator url="/pages/LoginRegistration/register/register">注册</navigator>
							</view>
							<view class="btnA">
								<button type="button" style="color: #FFFFFF; " @click="login1()">登&nbsp;录</button>
							</view>
						</view>

						<view v-else-if="current==2">
							<form>
								<view class="username">
									<image src="../../../static/icon/regi_icon/iconfont-phone.png" mode=""></image>
									<text>手&nbsp;机:</text>
									<input v-model="dataFrom2.mobile" @input="iponeinput" placeholder="请输入手机号"
										type="number" style="text-indent: 48rpx; width: 316rpx;
						height: 84rpx;
						margin-left: 22rpx;
						border-radius: 10rpx;
						box-shadow: inset 0px 2px 5px #9e9e9e80;" />
								</view>
								<view class="password">
									<view style="margin-left: -24rpx;display: flex;
    align-items: center;">
										<image style="width: 36rpx;height: 36rpx;" src="../../../static/icon/yzm.png"
											mode=""></image>
										<text>验证码:</text>
									</view>
									<input v-model="dataFrom2.verifyCode" placeholder="输入" type="number" style="text-indent: 48rpx;  width: 316rpx;
						height: 84rpx;
						margin-left: 22rpx;
						border-radius: 10rpx;
						box-shadow: inset 0px 2px 5px #9e9e9e80;" />
									<view>
										<button style=" padding-left: 4px;
    padding-right: 4px;
    color: rgb(250,248,255);
    background-color: rgb(164, 113, 251);
    position: absolute;
    width: 34%;
    height: 42px;
    right: 0%;
    bottom: 0px;
    text-align: center;
    line-height: 42px;
    font-size: 13px;" @click="yzm()">发送验证码</button>
									</view>
								</view>
							</form>
							<view class="sms">
								<navigator url="/pages/LoginRegistration/register/register">注册</navigator>
							</view>
							<view class="btnA">
								<button type="button" style="color: #FFFFFF; " @click="login2()">登&nbsp;录</button>
							</view>
						</view>
						<!-- 	<view class="btnB">
						<button type="button" @click="goNavto">注册</button>
					</view> -->
					</view>
					<view class="box2-a">
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		mapMutations,
		mapState
	} from 'vuex'
	import md5 from '@/until/md5/md5.js'
	import NavBar from '@/components/NavBar.vue'
	import uniRequest from '@/until/uni-request.js'
	export default {
		computed: { //加载数据过程loading
			...mapState(["isLoading"])
		},
		components: {
			NavBar
		},
		// created:{

		// },
		mounted() {
			//记住密码
					//缓存的账号
					const HBna = uni.getStorageSync('HBna');
					//缓存的密码
					const HBpa = uni.getStorageSync('HBpa');
							// console.log("缓存的账号:"+HBna)
							// console.log("缓存的密码:"+HBpa)
							//有缓存就赋值给文本没有就清空
						if (HBna && HBpa) {
							let hbusername=''
							HBna.forEach((item)=>{
								hbusername+=String.fromCharCode(item)
							})
							let hbpassword=''
							HBpa.forEach((item)=>{
								hbpassword+=String.fromCharCode(item)
							})
							this.dataFrom.username =hbusername ;
							this.dataFrom.password = hbpassword;
						} else {
							this.dataFrom.username = '';
							this.dataFrom.password = '';
						}
						
						const HBmo = uni.getStorageSync('HBmo');
						//缓存的密码
						const HBpa1 = uni.getStorageSync('HBpa1');
								// console.log("缓存的手机:"+HBmo)
								// console.log("缓存的密码:"+HBpa1)
								//有缓存就赋值给文本没有就清空
							if (HBmo && HBpa1) {
								let hbusermobile=''
								HBmo.forEach((item)=>{
									hbusermobile+=String.fromCharCode(item)
								})
								let hbpassword1=''
								HBpa1.forEach((item)=>{
									hbpassword1+=String.fromCharCode(item)
								})
								
								this.dataFrom1.mobile = hbusermobile;
								this.dataFrom1.password = hbpassword1;
							} else {
								this.dataFrom1.mobile = '';
								this.dataFrom1.password = '';
							}
		
		},
		onShow() {
			
			this.enable = true
			// this.$router.llj=1
			// console.log(this.$router);
		},
		onHide() {
			//页面销毁时，取消监听  
			this.enable = false
		},
		data() {
			return {
				rememberPsw: true,//复选框状态 默认勾选
				rememberPsw1:true,
				// 是否开启吸顶功能
				enable: true,
				isShow: false,
				msg: '',
				barStyle: {},
				current: 0,
				list: [{
						name: '账号登录'
					},
					{
						name: '手机登录'
					},
					{
						name: '短信登录'
					},

				],
				dataFrom: {
					username: '',
					password: '',
				},
				dataFrom1: {
					mobile: '',
					password: '',

				},
				dataFrom2: {
					mobile: '',
					verifyCode: ''
				},
				flag: true,
				flag1: true,
				username: "username",
				password: "password",
				passwordIcon: true,
				border: true
			}
		},
		methods: {
			passShow() {

				// this.flag1=!this.flag1
				this.flag = !this.flag
				console.log(this.flag);
				console.log(this.flag1);
			},
			passShow1() {

				this.flag1 = !this.flag1

				console.log(this.flag1);
			},
			fpNumInput(e) {
				const o = e.target;
				const inputRule = /[\W]/g //修改inputRule 的值
				this.$nextTick(function() {
					this.dataFrom.username = o.value.replace(inputRule, '');
				})
			},
			iponeinput(e) {
				const ipone = e.target
				var strTemp = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
				if (strTemp.test(ipone.value)) {
					// uni.showToast({icon:'none',title:'电话格式正确'});
					return
				} else {
					uni.showToast({
						icon: 'none',
						title: '请输入正确的电话'
					});
					return false
				}
			},
			open() {
				this.openTCdeng()
				this.isShow = true
				console.log(this.$store.state.mackNum1);
			},
			close1() {
				this.closeTCdeng()
				this.isShow = false
				console.log(this.$store.state.mackNum1);
			},
			...mapMutations(['openTCdeng', 'closeTCdeng', 'openTC2']),
			yzm() {
				uniRequest.post('base/sms/send', {
					"mobile": this.dataFrom2.mobile,

					"template": "login"

				}).then((res) => {
					if (res.data.code == "0000") {
						this.msg = "验证码已发送，请注意查收"
						this.open()
					} else {
						this.msg = res.data.msg
						this.open()
					}
					console.log(res);

				}).catch((err) => {
					console.log(err);
				});
			},
			//复选框
						checkboxChange: function(e) {
							console.log("复选框状态:"+e.detail.value.length);
							if (e.detail.value.length == 1) {
								//获取缓存的账号 赋值
								uni.getStorageSync('HBna',this.dataFrom.username);
								uni.getStorageSync('HBpa',this.dataFrom.password);
							} else {//销毁
								uni.removeStorageSync('HBna');
								uni.removeStorageSync('HBpa');              
							}
						},
						checkboxChange1: function(e) {
							console.log("复选框状态:"+e.detail.value.length);
							if (e.detail.value.length == 1) {
								//获取缓存的账号 赋值
								uni.getStorageSync('HBmo',this.dataFrom1.mobile);
								uni.getStorageSync('HBpa1',this.dataFrom1.password);
							} else {//销毁
								uni.removeStorageSync('HBmo');
								uni.removeStorageSync('HBpa1');              
							}
						},
			login() {
				if (this.rememberPsw) {
					const user=this.dataFrom.username;
					let bb = user.split('')
					let userlist=[]
					bb.forEach((item)=>{
						userlist.push(item.charCodeAt())
					})
					const password=this.dataFrom.password;
					let bb1 = password.split('')
					let passlist=[]
					bb1.forEach((item)=>{
						passlist.push(item.charCodeAt())
					})
					// console.log(cc);
												uni.setStorageSync('HBna',userlist);
												uni.setStorageSync('HBpa',passlist);
											} else {//销毁缓存
												uni.removeStorageSync('HBna');
												uni.removeStorageSync('HBpa');
											}
				this.dataFrom.password = md5(this.dataFrom.password)
				uniRequest.post('user/user/login', this.dataFrom).then((res) => {
					console.log(res);
					this.openTC2()
					if (res.data.code == '0000') {
						
						
						this.dataFrom.username = '',

							uni.setStorageSync('token', res.headers.authorization)
						uni.setStorageSync('HeroicGramtoken', res.headers.authorization)
						uni.setStorageSync('shuaxin', 0)
						// uni.setStorageSync('tokencode',res.data.code)
						uni.navigateTo({
							url: '/pages/HomePage/PersonalCenter/PersonalCenter',
							// success(){
							// 		 let page = getCurrentPages().pop();  //跳转页面成功之后
							//              if (!page) return;  
							//              page.onLoad(); //如果页面存在，则重新刷新页面
							// 	  }
						});
					} else if (res.data.code == '1001') {
						this.msg = res.data.msg
						this.open()
						// alert("登录失败") 
					}
					this.dataFrom.password = ''
					// console.log(res.headers.authorization);
				}).catch((err) => {
					console.log(err);
				});

			},
			login1() {
				if (this.rememberPsw1) {
					const mobile=this.dataFrom1.mobile;
					let bb = mobile.split('')
					let mobilelist=[]
					bb.forEach((item)=>{
						mobilelist.push(item.charCodeAt())
					})
					const password=this.dataFrom1.password;
					let bb1 = password.split('')
					let passlist1=[]
					bb1.forEach((item)=>{
						passlist1.push(item.charCodeAt())
					})
					
					
												uni.setStorageSync('HBmo', mobilelist);
												uni.setStorageSync('HBpa1', passlist1);
											} else {//销毁缓存
												uni.removeStorageSync('HBmo');
												uni.removeStorageSync('HBpa1');
											}
				this.dataFrom1.password = md5(this.dataFrom1.password)
				uniRequest.post('user/user/login', this.dataFrom1).then((res) => {
					console.log(res);

					this.openTC2()
					if (res.data.code == '0000') {
						this.dataFrom1.mobile = '',

							uni.setStorageSync('token', res.headers.authorization)
						uni.setStorageSync('HeroicGramtoken', res.headers.authorization)
						uni.setStorageSync('shuaxin', 0)
						uni.navigateTo({
							url: '/pages/HomePage/PersonalCenter/PersonalCenter',
							// success(){
							// 		 let page = getCurrentPages().pop();  //跳转页面成功之后
							//              if (!page) return;  
							//              page.onLoad(); //如果页面存在，则重新刷新页面
							// 	  }
						});

					} else if (res.data.code == '1001') {
						// alert("登录失败")
						this.msg = res.data.msg
						this.open()
					}
					this.dataFrom1.password = ''
				}).catch((err) => {
					console.log(err);
				});

			},
			login2() {
				// this.dataFrom2.password=md5(this.dataFrom2.password)
				uniRequest.post('user/user/login', this.dataFrom2).then((res) => {
					console.log(res);
					this.openTC2()
					if (res.data.code == '0000') {
						this.dataFrom2.mobile = '',
							this.dataFrom2.verifyCode = ''
						uni.setStorageSync('token', res.headers.authorization)
						uni.setStorageSync('HeroicGramtoken', res.headers.authorization)
						uni.setStorageSync('shuaxin', 0)
						uni.navigateTo({
							url: '/pages/HomePage/PersonalCenter/PersonalCenter',
							// success(){
							// 		 let page = getCurrentPages().pop();  //跳转页面成功之后
							//              if (!page) return;  
							//              page.onLoad(); //如果页面存在，则重新刷新页面
							// 	  }	
						});
					} else if (res.data.code == '1001') {
						// alert("登录失败")
						this.msg = res.data.msg
						this.open()
					}
				}).catch((err) => {
					console.log(err);
				});

			},
			sectionChange(index) {
				this.current = index;
				console.log(this.current);

			},
			change(e) {
				console.log('change', e);
			},
			goNavto() {
				this.$router.push('/pages/LoginRegistration/register/register')

				// uni.navigateTo({
				// 	url: "/pages/LoginRegistration/register/register"
				// })
			}
		}
	}
</script>

<style scoped lang="scss">
	@-webkit-keyframes tdtc {
		0% {
			transform: scale(0.8); 
			// transform: scale(0.8);  
			opacity: 0.5;  
		}

	45%{
		transform: scale(1);
		opacity: 1; 
	}
	
		100% {
			transform: scale(1);
			opacity: 1; 
		}
	}
	.TC {
		transform-origin:350rpx 500rpx;
		animation-timing-function:cubic-bezier(0.01, 1.24, 0.08, 1.36);
		animation-name:tdtc;
		animation-duration:0.9s;
		
		animation-iteration-count:1;
		animation-play-state: running;
		// animation-delay:200ms;
		.toptext {
			position: absolute;
			// top: -8%;
			top: 100rpx;
			left: 35%;
			z-index: 999;
			background-color: #fff;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			.text-a {

				font-size: 46rpx;
			}

			.text-b {
				color: rgb(148, 113, 254);
				font-size: 32rpx;
			}
		}

		height: 100%;
		background-color: rgb(255, 255, 255);

		// background: linear-gradient(#7a52c0, #d7d7d7) no-repeat;
		.title {
			text-align: center;
			line-height: 100rpx;
			font-size: 60rpx;
			color: rgb(164, 133, 237);
		}

		.box {
			z-index: 999;
			background-color: #fff;

			.box1 {

				// margin-top: 20rpx;
				.box1-a {
					width: 100%;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					height: 300px;
					align-items: center;

					image {
						width: 552rpx;
						height: 319rpx;
					}
				}
			}

			.send {
				position: absolute;
				right: 52rpx;

				uni-button {
					border-radius: 100rpx;
					height: 92rpx;
					line-height: 92rpx;
					color: #fff;
					width: 144rpx;
					background: rgb(121, 72, 234);
					font-size: 28rpx;
				}
			}

			.box2-a {
				width: 94%;
				height: 16px;
				background-color: #fffefe7d;
				box-shadow: 0px 5px 50px #9e9e9e3b;
				border-radius: 0rem 0rem 10px 10px;
				/* opacity: 0.4; */
				position: absolute;
				left: 3%;
				bottom: -16px;
				// /* z-index: -1;
			}

			.u-input--border[data-v-fdbb9fe6] {
				border-radius: 100rpx;
				height: 96rpx;
				box-sizing: border-box;
				padding-top: 8rpx !important;
				margin-left: 10rpx;
			}

			.username {
				font-size: 18px;
				display: flex;
				align-items: center;

				image {
					width: 16px;
					height: 16px;
					margin-right: 4px;
				}
			}

			.password {
				font-size: 18px;
				display: flex;
				align-items: center;
				margin-top: 30px;

				image {
					width: 16px;
					margin-right: 4px;
					height: 16px;
				}
			}

			.sms {
				display: flex;
				justify-content: end;
				color: rgb(164, 133, 237);
				position: absolute;
				bottom: 33%;
				right: 11%;
			}

			// z-index: 99;
			background-color: #fff;
			box-sizing: border-box;
			padding: 48rpx;
			box-shadow: 0px 10rpx 100rpx #9e9e9e80;
			position: absolute;
			background: #fff;
			width: 80%;
			height: 764rpx;
			border-radius: 2%;
			top: 228rpx;
			left: 10%;

			.btnA {

				width: 67%;
				margin: 0px auto;
				// margin-top: 40%;

				uni-button {
					border-radius: 64rpx;
					background: linear-gradient(to right, #A272FC, #DE62D2);
				}
			}

			.btnB {
				width: 60%;

				uni-button {
					margin-top: 20rpx;
					border-radius: 32px;
					color: #7a52c0;
				}

				margin: 0px auto;
			}
		}
	}



	.uni-input-placeholder {
		color: rgb(189, 189, 189);
		font-size: 28rpx;
	}

	::v-deep .u-sticky {
		height: 100rpx;
		// width:	100%;
		// display: flex;
		// justify-content: center;
		// align-items: center;
	}

	::v-deep .u-tabs__wrapper__nav__item {
		padding: 0 32rpx;
		// width: 200rpx;
	}

	uni-page-body {
		height: 100%;
		background-color: rgb(255, 255, 255);

		// background: linear-gradient(#7a52c0, #d7d7d7) no-repeat;
		.title {
			.til {
				display: flex;
				align-items: center;
			}

			display: flex;
			align-items: center;
			justify-content: space-evenly;
			margin-top: 28rpx;
			// margin: 0px auto;
			// text-align: center;
			line-height: 110rpx;
			font-size: 60rpx;
			color: rgb(164, 133, 237);

			image {
				width: 55rpx;
				height: 55rpx;
				margin-right: 10rpx;
			}
		}

		.box {
			.box1 {
				.box1-a {
					form {
						display: flex;
						justify-content: center;
						margin-top: 76rpx;
					}
				}
			}

			.box2-a {
				width: 94%;
				height: 16px;
				background-color: #fffefe7d;
				box-shadow: 0px 5px 50px #9e9e9e3b;
				border-radius: 0rem 0rem 10px 10px;
				/* opacity: 0.4; */
				position: absolute;
				left: 3%;
				bottom: -16px;
				// /* z-index: -1;
			}

			.u-input--border[data-v-fdbb9fe6] {
				border-radius: 100rpx;
				height: 96rpx;
				box-sizing: border-box;
				padding-top: 8rpx !important;
				margin-left: 10rpx;
			}

			.username {
				color: rgb(148, 113, 254);
				font-size: 18px;
				display: flex;
				align-items: center;

				image {
					width: 16px;
					height: 16px;
					margin-right: 4px;
				}
			}

			.password {
				color: rgb(148, 113, 254);
				font-size: 18px;
				display: flex;
				align-items: center;
				margin-top: 30px;
				position: relative;

				image {
					width: 16px;
					margin-right: 4px;
					height: 16px;
				}
			}

			.sms {
				display: flex;
				justify-content: end;
				color: rgb(121, 72, 234);
				position: absolute;
				bottom: 42%;
				right: 12%;
				font-size: 32rpx;
			}

			box-sizing: border-box;
			padding: 48rpx 20rpx;
			// padding-top: 90rpx;
			box-shadow: 0px 5px 50px #9e9e9e80;

			position: absolute;
			background: #fff;
			width: 86%;
			height: 928rpx;
			border-radius: 5%;
			top: 264rpx;
			left: 7%;

			.btnA {

				width: 40%;
				margin: 0px auto;
				margin-top: 28%;

				uni-button {
					border-radius: 64rpx;
					background: linear-gradient(to right, #A272FC, #DE62D2);
				}
			}

			.btnB {
				width: 53%;

				uni-button {
					margin-top: 20rpx;
					border-radius: 32px;
					color: #7a52c0;
				}

				margin: 0px auto;
			}
		}
	}
</style>
